//
//  SuperviseReportVC.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/1/5.
//
// 【首页-检查监督】任务报告-列表

import Foundation
import UIKit

class SuperviseReportVC: SubLevelViewController {
    let headerV = BSSearchButton(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 60))
    let tableView = UITableView(frame: .zero, style: .plain)
    
    let datas = [1, 2, 3, 4]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.navBarStyle(.white)
        view.backgroundColor = .white
        title = "任务报告"
        setupNavItems()
        setupUI()
    }
    
    @objc func showSearchTapped() {
        let searchVC = SuperviseSearchVC()
        searchVC.didSelectItemWith = { (item) -> () in
//            self.deptName = dept.deptName
//            self.deptId = dept.deptId
        }
        navigationController?.pushViewController(searchVC, animated: true)
    }
    
    
    @objc func searchTapped() {
//        let searchVC = UnarmedSearchVC()
//        searchVC.didSelectItemWith = { (item) -> () in
//            self.deptName = dept.deptName
//            self.deptId = dept.deptId
//        }
//        navigationController?.pushViewController(searchVC, animated: true)
    }
    
    // MARK: - Setup
    
    func setupUI() {
        tableView.separatorStyle = .none
        tableView.showsVerticalScrollIndicator = false
        tableView.backgroundColor = .white
        tableView.delegate = self
        tableView.dataSource = self
        view.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
        }
        
        headerV.titleL.text = "请输入关键字"
//        headerV.padding = 25
        headerV.addTarget(self, action: #selector(showSearchTapped), for: .touchUpInside)
        tableView.tableHeaderView = headerV
    }
    
    func setupNavItems() {
        let searchBtn = UIButton(type: .custom)
        searchBtn.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
        searchBtn.contentEdgeInsets = UIEdgeInsets(top: 0, left: 50, bottom: 0, right: 0)
        searchBtn.setImage(UIImage(named: "ic_search"), for: .normal)
        searchBtn.addTarget(self, action: #selector(searchTapped), for: .touchUpInside)
        let searchBar = UIBarButtonItem(customView: searchBtn)
    
        navigationItem.rightBarButtonItems = [searchBar]
    }
}

extension SuperviseReportVC: UITableViewDataSource, UITableViewDelegate {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return datas.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let data = datas[indexPath.row]
        let ID : String = "SuperviseReportCell"
            
        var cell = tableView.dequeueReusableCell(withIdentifier: ID)
        if cell == nil {
            cell = SuperviseReportCell(style: .subtitle, reuseIdentifier: ID)
        }
        
        (cell as? SuperviseReportCell)?.reload(withModal: data)
        return cell!
    }

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return 145
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//        navigationController?.pushViewController(NotiDetailVC(), animated: true)
    }
    
}
